targets = main

BIN_DIR = ./

C_SRCS    := 

CPP_SRCS  := main.cpp
#CPP_SRCS  += 

HEAD_FILES += 

C_OBJS    := $(patsubst %.c,   %.o, $(C_SRCS))
CPP_OBJS  := $(patsubst %.cpp, %.o, $(CPP_SRCS))

# CFILES += $(foreach dir, utils/aaccodec, $(wildcard $(dir)/*.c))

#####################################################

INCPATH  := -I./include -I./include/ssicloud

CFLAGS   := -pipe -Wall
CXXFLAGS := -pipe -Wall -std=c++11
LIBS	 += -lssicloud -lcurl -lssl -lcrypto
ARCH	?= arm
CROSS_COMPLILE ?= /opt/sdk/rk3568/aarch64-linux-gcc-v12.3/bin/aarch64-linux-
SYSROOT ?= /opt/sdk/rk3568/aarch64-linux-gcc-v12.3/aarch64-buildroot-linux-gnu/sysroot

ifeq ($(ARCH),arm)

#INCPATH  += 
CFLAGS   += $(INCPATH)
CXXFLAGS += $(INCPATH)

LDFLAGS  += -Wl,-rpath,./lib
LIBS     += -L./lib

CC	 =$(CROSS_COMPLILE)gcc --sysroot=$(SYSROOT)
CXX	 =$(CROSS_COMPLILE)g++ --sysroot=$(SYSROOT)
STRIP=$(CROSS_COMPLILE)strip 
LINK =$(CROSS_COMPLILE)g++ --sysroot=$(SYSROOT)

else

#INCPATH  += 
CFLAGS   += $(INCPATH)
CXXFLAGS += $(INCPATH)

LDFLAGS  += -Wl,-rpath,./lib
LIBS     += -L./lib

CROSS_COMPLILE=
CC	 = gcc
CXX	 = g++
STRIP= strip
LINK = g++
endif


CP    = cp
MKDIR = mkdir -p



#注意-lasound 库必须放在最后才能通过变异
#gcc中库的链接顺序是从右往左进行，所以要把基础实现的库放在最后

.PHONY:all $(targets)

# ifeq ("$(wildcard $(OBJ_DIR))","")
# $(shell $(MKDIR) $(OBJ_DIR))
# endif

#ifeq ("$(wildcard $(BIN_DIR))","")
#$(shell $(MKDIR) $(BIN_DIR))
#endif

all: $(targets)

########################################################################
# V=1
Q=@  
E=echo
ifeq ($(V), 1)
Q=   
E=true
endif

$(targets):  $(C_OBJS) $(CPP_OBJS)
	$(Q)$(LINK) -o $(BIN_DIR)$@ $^ $(LIBS) $(LDFLAGS)
	@$(E) "  CC " $@
      
%.o: %.c $(HEAD_FILES)
	$(Q)$(CC) $(CFLAGS) -c $< -o $@
	@$(E) "  CC " $<

%.o: %.cpp $(HEAD_FILES)
	$(Q)$(CXX) $(CXXFLAGS) -c $< -o $@
	@$(E) "  CC " $<

clean:
	-rm $(C_OBJS) $(CPP_OBJS) -rf

distclean:
	-rm $(BIN_DIR)$(targets) $(C_OBJS) $(CPP_OBJS) -rf





